package com.lxq.LeetCode.firstBadVersion;

public class Solution {
    public static void main(String[] args) {

    }

    public static boolean isBadVersion(int version) {
        return false;
    }

    public static int firstBadVersion(int n) {
        if (n == 1) {
            return 1;
        }
        if (n==2){
            if (isBadVersion(2)){
                return 2;
            }else {
                return 1;
            }
        }
        int res = 1;
        int p1 = 1;
        int p2 = n;
        while (p2 > p1 + 1) {
            int p = (p2 - p1) / 2;
            if (isBadVersion(p)) {
                p2 = p;
            } else {
                p1 = p;
            }
        }
        res = p2;
        return res;
    }
}
